//app.js
// 埋点
const gio = require("utils/gio-minp.js").default;
let conf = {
  version: '1.0',
  followShare: true
}
gio('init', '8e69f13ef5364c9f', 'wxdc7c59125e20a8c0', conf);
App({
  onLaunch: function () {
    let env = 'prod'
    if (env == 'prod') this.globalData.staticImgUrl = 'https://content.igola.com/static/WECHATAPP/images/common/'
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
              gio('setVisitor', res.userInfo)
            }
          })
        }
      }
    })

    // 获取系统信息
    wx.getSystemInfo({
      success: res => {
        this.globalData.model = res.model
        if (this.globalData.model.indexOf('iPhone X') >= 0) {
          this.globalData.model = 'iPhone X'
        }
        this.globalData.systemInfo = res
        this.globalData.screenHeight = res.screenHeight
      }
    })
    this.getShareData()
  },
  getShareData() {
    let imgUrl_newYear = this.globalData.staticImgUrl + 'share-newYear.png'
    let imgUrl_pig = this.globalData.staticImgUrl + 'share-pig.png'
    let obj1 = {
      'text': '请回答2019，揭秘你的新年运势！',
      'imgUrl': imgUrl_newYear
    },
      obj2 = {
        'text': '快转发这份好运让你猪事大吉',
        'imgUrl': imgUrl_pig
      },
      obj3 = {
        'text': '猪猪猪年神预测，2019给你好运势!',
        'imgUrl': imgUrl_pig
      },
      obj4 = {
        'text': '新年好运，摇一摇即刻拥有～',
        'imgUrl': imgUrl_newYear
      }
    this.globalData.shareData = [obj1, obj2, obj3, obj4]
  },
  globalData: {
    userInfo: null,
    model: 'iphone 6',
    systemInfo: null,
    screenHeight: 0,
    drawData: null,
    staticImgUrl: 'http://devcontent.igola.com/static/WECHATAPP/images/common/',
    fontScale: false,
    shareData: null
  }
})